﻿package site1.views.navigation 
{
	import site1.SiteApp;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import fwk.siteManager2.events.SiteManagerEvent;
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	public class Navigation 
	{
		private var _mc:MovieClip;
		private var _currentNav:MovieClip;
		
		
		public function get mc():MovieClip
		{
			return _mc;
			
		}
		public function Navigation(mc:MovieClip) 
		{
			_mc = mc;
			_mc.nav1.alpha = 0.7;
			_mc.nav2.alpha = 0.7;
			_mc.nav3.alpha = 0.7;
			
			_mc.nav1.addEventListener(MouseEvent.CLICK, onClick);
			_mc.nav2.addEventListener(MouseEvent.CLICK, onClick);
			_mc.nav3.addEventListener(MouseEvent.CLICK, onClick);
			
			
			SiteApp.main.addEventListener(SiteManagerEvent.CONTEXT_CHANGE, refreshNav);
			
			
			
		}
		
		private function onClick(evt:MouseEvent)
		{
			switch(evt.currentTarget.name)
			{
				case "nav1":
					SiteApp.main.loadAndDisplayPage("/page1", true );
				break;
				case "nav2":
					SiteApp.main.loadAndDisplayPage("/page2", true );
				break;
				case "nav3":
					SiteApp.main.loadAndDisplayPage("/page3", true );
				break;
			}
			
		}
		
		private function refreshNav(evt:SiteManagerEvent)
		{
			if (_currentNav != null) _currentNav.alpha = 0.7;
			
			SiteApp.main.debugIt("--------> Event SiteManagerEvent.CONTEXT_CHANGE deepLink = " + SiteApp.main.deepLink);
			
			var tabChaine:Array = SiteApp.main.deepLink.split(SiteApp.main.splitDeepLink);
			
			switch(tabChaine[1] as String)
			{
				case "page1":
					_mc.nav1.alpha = 1;
					_currentNav = _mc.nav1;
				break;
				case "page2":
					_mc.nav2.alpha = 1;
					_currentNav = _mc.nav2;
				break;
				case "page3":
					_mc.nav3.alpha = 1;
					_currentNav = _mc.nav3;
				break;
			}
			
		}
	}
	
}